package com.wdh.minio.service;

import com.wdh.minio.bean.Order;
import com.wdh.minio.bean.PayResult;
import com.wdh.minio.event.OrderCreateEvent;
import com.wdh.minio.event.PayResultEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

@Service
public class OrderService {

    @Autowired
    private ApplicationEventPublisher eventPublisher;

    public void createOrder() {
        Order order = new Order();
        order.setId("1");
        order.setName("测试订单");
        order.setAddress("上海");
        order.setPhone("123456789");
        order.setEmail("123456@qq.com");
        eventPublisher.publishEvent(new OrderCreateEvent(order, "订单创建成功"));
    }

    public void publishPayEvent() {
        PayResult result = new PayResult();
        result.setOrderId("1");
        result.setPayId("1");
        result.setPayTime("2023-05-05 12:00:00");
        result.setPayStatus("success");
        eventPublisher.publishEvent(new PayResultEvent(result, "订单支付成功"));
    }
}
